package edu.sctu;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.rowset.serial.SerialException;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;

import static java.lang.System.out;

/**
 * Created by Administrator on 2018/6/11.
 */
public class AddUserServlet extends HttpServlet{
    @Override
            protected void doPost(HttpServletRequest request,
                                  HttpServletResponse response)
            throws ServletException,IOException{

        String username=request.getParameter("username");
        String password=request.getParameter("password");

        Connection connection=null;
        Statement statement=null;

        String sql="insert into t_users(username,pasword)values('"+username+"','"+password+"')";



            try {
                Class.forName("com.mysql.jdbc.Driver");
                connection=DriverManager.getConnection(
                        "jdbc:mysql://47.104.80.155:3306/javaweb",
                        "javaweb",
                        "JAVAweb123!@#");

                        statement=connection.createStatement();
                statement.execute(sql);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e1) {
                e1.printStackTrace();
            }

        PrintWriter out=response.getWriter();
        out.write("<h1>成功删除用户</h1>");
        out.write("<a href='userList.jsp'>返回页面</a>");
        }



    }




